<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">{{Lang.lang('地址')}}</view>
			<view class="back"></view>
			<!-- <view class="rule">规则</view> -->
		</view>
		<view class="clear_box"></view>

		<view class="page_content">
			<block v-for="(item, index) in list" :key="'address' + index">
				<view class="address_list" @click="userAddressDef(item.id)">
					<view class="tick iconfont icon-kongxinduigou" :class="item.is_def == 1 ? 'tickColor' : ''"></view>
					<view class="text_box">
						<view class="title">{{item.city}} {{item.detail}}</view>
						<view class="name_box">
							<view class="name">{{item.consigner}}</view>
							<view class="phone">{{item.phone}}</view>
						</view>
					</view>
					<!-- <view class="icon iconfont icon-bianji4"></view> -->
					<view class="icon iconfont ">
						<span class="icon-changyonggoupiaorenshanchu" @click="userAddressDel(item.id)"></span>
					</view>
				</view>
			</block>

			<view class="confirm" data-url="/pages/mall/address/manage" @click="gotopage">{{Lang.lang('添加地址')}}</view>
		</view>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				lang: 'en',
				link: '',
				pupu: false,
				scrrol: false,
				info: '',
				list: []

			}
		},
		onLoad() {

		},
		onShow() {
			let that = this;
			this.lang = uni.getStorageSync('_language');
			that.loadData();
		},
		methods: {
			setTickStyle(e) {
				let that = this;
				let index = e.currentTarget.dataset.index;

			},
			loadData() {
				let that = this;
				that.Net._post('api/shop/userAddressList', {}, res => {
					if (res.code == 200) {
						that.list = res.data.list
						//console.log(res);

					}
				});
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
			userAddressDef(id) {
				let that = this
				that.Net._post('api/shop/userAddressDef', {
					id: id
				}, res => {
					if (res.code == 200) {
						// that.Msg.Success(res.msg)
						setTimeout(function() {
							that.loadData();
						}, 500)
					}
				});

			},
			userAddressDel(id) {
				let that = this
				that.Msg.Confirm(that.Lang.lang('確定刪除嗎') + '?', that.Lang.lang('取消'), that.Lang.lang('確定'), function(res) {
					if (res.confirm) {
						that.Net._post('api/shop/userAddressDel', {
							id: id
						}, res => {
							if (res.code == 200) {
								that.loadData();
							}
						});
					}
				})
			}
		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
	}
</script>

<style>
	.header {
		background-color: transparent !important;
	}

	.header .text {
		text-align: center;
	}

	.page_content {
		width: 92%;
		margin: 0 auto;
	}

	.scrrolHeader {
		width: 100%;
		background-color: #1A1A1A !important;

	}

	.address_list {
		width: 100%;
		background-color: #1A1A1A;
		padding: 5vw 4vw;
		display: flex;
		margin-top: 4%;
		border-radius: 4vw;
	}

	.address_list .tick {
		width: 8vw;
		font-size: 6vw;
		color: #fff;
		text-align: left;
	}

	.address_list .icon {
		width: 8vw;
		font-size: 5vw;
		color: #fff;
		text-align: right;
	}

	.address_list .text_box {
		flex: 1;
	}

	.address_list .text_box .title {
		font-size: 3.5vw;
		color: #fff;
		font-weight: bold;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}

	.address_list .text_box .name_box {
		display: flex;
		margin-top: 2vw;
	}

	.address_list .text_box .name_box .name {
		font-size: 3.5vw;
		color: #fff;
	}

	.address_list .text_box .name_box .phone {
		font-size: 3.5vw;
		color: #fff;
		margin-left: 4vw;
	}

	.tickColor {
		color: #0155FF !important;
	}
</style>